home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #1 / Amiga Plus CD - 2000 - No. 1.iso / Tools / Dev / Meshwriter_lib / Library / samples / cubetower.c < prev    next >
C/C++ Source or Header  |  1999-12-03  |  5KB  |  148 lines

  1. /*
  2. **      $VER: cubetower.c 1.00 (20.3.1999)
  3. **
  4. **      Creation date     : 20.3.1999
  5. **
  6. **      Description       :
  7. **         MeshWriter testprogram shape module.
  8. **
  9. **
  10. **      Written by Stephan Bielmann
  11. **
  12. */
  13.  
  14. /*************************** Includes *******************************/
  15.  
  16. #include <meshwriter/meshwriter.h>
  17. #include <pragma/meshwriter_lib.h>
  18.  
  19. /**************************** Defines *******************************/
  20.  
  21. /*********************** Type definitions ***************************/
  22.  
  23. /********************** Private functions ***************************/
  24. static void cube(ULONG mesh, ULONG color) {
  25.   TOCLVertex v1,v2,v3,v4,v5,v6,v7,v8;
  26.  
  27.   v1.x=-0.5,v1.y=-0.5,v1.z=-0.5;
  28.   v2.x=0.5,v2.y=-0.5,v2.z=-0.5;
  29.   v3.x=0.5,v3.y=0.5,v3.z=-0.5;
  30.   v4.x=-0.5,v4.y=0.5,v4.z=-0.5;
  31.   v5.x=-0.5,v5.y=-0.5,v5.z=0.5;
  32.   v6.x=0.5,v6.y=-0.5,v6.z=0.5;
  33.   v7.x=0.5,v7.y=0.5,v7.z=0.5;
  34.   v8.x=-0.5,v8.y=0.5,v8.z=0.5;
  35.  
  36.   MWLMeshTriangleAdd(mesh,color,&v1,&v2,&v3);
  37.   MWLMeshTriangleAdd(mesh,color,&v1,&v3,&v4);
  38.  
  39.   MWLMeshTriangleAdd(mesh,color,&v5,&v6,&v7);
  40.   MWLMeshTriangleAdd(mesh,color,&v5,&v7,&v8);
  41.  
  42.   MWLMeshTriangleAdd(mesh,color,&v4,&v1,&v5);
  43.   MWLMeshTriangleAdd(mesh,color,&v4,&v5,&v8);
  44.  
  45.   MWLMeshTriangleAdd(mesh,color,&v7,&v6,&v2);
  46.   MWLMeshTriangleAdd(mesh,color,&v7,&v2,&v3);
  47.  
  48.   MWLMeshTriangleAdd(mesh,color,&v1,&v6,&v5);
  49.   MWLMeshTriangleAdd(mesh,color,&v1,&v2,&v6);
  50.  
  51.   MWLMeshTriangleAdd(mesh,color,&v4,&v8,&v7);
  52.   MWLMeshTriangleAdd(mesh,color,&v4,&v7,&v3);
  53. }
  54.  
  55. /********************** Public functions ****************************/
  56.  
  57. /********************************************************************\
  58. *                                                                    *
  59. * Name         : cubetower                                           *
  60. *                                                                    *
  61. * Description  : Draws a tower of cubes with the help of the scaling *
  62. *                and translation functions.                          *
  63. *                                                                    *
  64. * Arguments    : mesh    IN  : An initialized mesh handle.           *
  65. *                                                                    *
  66. * Comment      :                                                     *
  67. *                                                                    *
  68. \********************************************************************/
  69. void cubetower (ULONG mesh) {
  70.   ULONG red,green,blue,white,black;
  71.   TOCLColor color;
  72.   TOCLVertex vt,vs;
  73.   
  74.   MWLMeshMaterialAdd(mesh,&red);
  75.   color.r=255,color.g=0,color.b=0;
  76.   MWLMeshMaterialNameSet(mesh,red,"Red");
  77.   MWLMeshMaterialDiffuseColorSet(mesh,red,&color);
  78.   MWLMeshMaterialShininessSet(mesh,red,0);
  79.   MWLMeshMaterialTransparencySet(mesh,red,0);
  80.  
  81.   MWLMeshMaterialAdd(mesh,&green);
  82.   color.r=0,color.g=255,color.b=0;
  83.   MWLMeshMaterialNameSet(mesh,green,"Green");
  84.   MWLMeshMaterialDiffuseColorSet(mesh,green,&color);
  85.   MWLMeshMaterialShininessSet(mesh,green,0);
  86.   MWLMeshMaterialTransparencySet(mesh,green,0);
  87.  
  88.   MWLMeshMaterialAdd(mesh,&blue);
  89.   color.r=0,color.g=0,color.b=255;
  90.   MWLMeshMaterialNameSet(mesh,blue,"Blue");
  91.   MWLMeshMaterialDiffuseColorSet(mesh,blue,&color);
  92.   MWLMeshMaterialShininessSet(mesh,blue,0);
  93.   MWLMeshMaterialTransparencySet(mesh,blue,0);
  94.  
  95.   MWLMeshMaterialAdd(mesh,&white);
  96.   color.r=255,color.g=255,color.b=255;
  97.   MWLMeshMaterialNameSet(mesh,white,"White");
  98.   MWLMeshMaterialDiffuseColorSet(mesh,white,&color);
  99.   MWLMeshMaterialShininessSet(mesh,white,0);
  100.   MWLMeshMaterialTransparencySet(mesh,white,0);
  101.  
  102.   MWLMeshMaterialAdd(mesh,&black);
  103.   color.r=0,color.g=0,color.b=0;
  104.   MWLMeshMaterialNameSet(mesh,black,"Black");
  105.   MWLMeshMaterialDiffuseColorSet(mesh,black,&color);
  106.   MWLMeshMaterialShininessSet(mesh,black,0);
  107.   MWLMeshMaterialTransparencySet(mesh,black,0);
  108.  
  109.   MWLMeshNameSet(mesh,"Cubetower");
  110.  
  111.   vs.x=10,vs.y=10,vs.z=10;
  112.  
  113.   MWLMeshScaleChange(mesh,&vs,CTMSET);
  114.   cube(mesh,black);
  115.  
  116.   vs.x=2,vs.y=2,vs.z=2;
  117.  
  118.   MWLMeshScaleGet(mesh,&vt);
  119.   vt.x=0;vt.y=0;vt.z-=1;
  120.  
  121.   MWLMeshScaleChange(mesh,&vs,CTMSUB);
  122.   MWLMeshTranslationChange(mesh,&vt,CTMSET);
  123.   cube(mesh,red);
  124.  
  125.   MWLMeshScaleGet(mesh,&vt);
  126.   vt.x=0;vt.y=0;vt.z-=1;
  127.  
  128.   MWLMeshScaleChange(mesh,&vs,CTMSUB);
  129.   MWLMeshTranslationChange(mesh,&vt,CTMADD);
  130.   cube(mesh,blue);
  131.  
  132.   MWLMeshScaleGet(mesh,&vt);
  133.   vt.x=0;vt.y=0;vt.z-=1;
  134.  
  135.   MWLMeshScaleChange(mesh,&vs,CTMSUB);
  136.   MWLMeshTranslationChange(mesh,&vt,CTMADD);
  137.   cube(mesh,green);
  138.  
  139.   MWLMeshScaleGet(mesh,&vt);
  140.   vt.x=0;vt.y=0;vt.z-=1;
  141.  
  142.   MWLMeshScaleChange(mesh,&vs,CTMSUB);
  143.   MWLMeshTranslationChange(mesh,&vt,CTMADD);
  144.   cube(mesh,white);
  145. }
  146.  
  147. /************************* End of file ******************************/
  148.